// 6.52 一棵二叉树的繁茂度定义为各层结点数的最大值与树的高度的乘积。试写一算法，求二叉树的繁茂度。
#include <stdio.h>
#include <stdlib.h>
#include "E:\Desktop\data_struct\5TREE\1_bin_tree\creat.h"

int fun_6_52(tree *root)
{
    tree *que[100];
    int rear, front;
    rear = front = 0;
    if (!root)
        return 0;
    que[rear++] = root;
    int m, n;
    m = 1, n = 0;
    int max = -1;
    int level = 0;
    while (front < rear)
    {
        tree *t = que[front++];
        m--;
        if (t->left)
        {
            que[rear++] = t->left;
            n++;
        }
        if (t->right)
        {
            que[rear++] = t->right;
            n++;
        }
        if (m == 0)
        {
            if (n > max)
                max = n;
            m = n;
            n = 0;
            level++;
        }
    }
    return max * level;
}

int main()
{
    /*******************code*******************/
    int n = 15;
    int a1[15] = {1,
                  2, 3,
                  4, 5, NULL, NULL,
                  9, 6, 7, 8, NULL, NULL, NULL, NULL};
    tree *root;
    CreatTree(root, a1, n, 0);
    printf("%d", fun_6_52(root));
    /******************************************/
    printf("\n\n****************************\n");
    printf("Press Enter key to continue\n");
    getchar();
    return 0;
    /******************************************/
}
